function promiseAll(promises: Promise<any>[]): Promise<any> {
    return new Promise((resolve, reject) => {
        let count = 0, len = promises.length, result: any[] = []
        for(let i = 0; i < len; i++) {
            promises[i].then(res => {
                result.push(res)
                count++
                if(count === len) {
                    resolve(result)
                }
            }, err => {
                reject(err)
            })
        }
    })
}

const p1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(1)
    }, 2000);
})

const p2 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(2)
    }, 3000);
})

const p3 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(3)
    }, 1000);
})

promiseAll([p1, p2, p3]).then(res => {
    console.log(res)
})

export {}